import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
    meta: {
      title: "首页"
    }
  },
  // 科一图标技巧
  {
    name: "IconTechnical",
    path: "/IconTechnical",
    component: () => import("../views/exam/IconTechnical.vue"),
    meta: {
      title: "图标技巧"
    }
  },
  //
  {
    name: "TrafficTips",
    path: "/TrafficTips/:type",
    component: () => import("../views/exam/TrafficTips.vue")
  },

  // 图标列表
  {
    name: "TrafficSign",
    path: "/TrafficSign/:type",
    component: () => import("../views/exam/TrafficSign.vue"),
    meta: {
      keepAlive: true
    }
  },

  // 图标详解
  {
    name: "DetailedAnnotation",
    path: "/DetailedAnnotation/:id",
    component: () => import("../views/exam/DetailedAnnotation.vue"),
    meta: {
      title: "图标详解"
    }
  },

  // 学车学堂
  {
    name: "CardSchool",
    path: "/CardSchool/:lid/:type",
    component: () => import("../views/Homepage/CardSchool.vue"),
    meta: {
      title: "学车学堂"
    }
  },

  // 学车学堂详情
  {
    name: "EvenMore",
    path: "/EvenMore/:type",
    component: () => import("../views/Homepage/EvenMore.vue"),
    meta: {
      title: "学车学堂"
    }
  },

  // 驾考秘籍
  {
    name: "Esoterica",
    path: "/Esoterica/:type",
    component: () => import("../views/Homepage/Esoterica.vue"),
    meta: {
      title: "驾考秘籍"
    }
  },

  // 秘籍详情
  {
    name: "SecretDetails",
    path: "/SecretDetails/:lid",
    component: () => import("../views/Homepage/SecretDetails.vue"),
    meta: {
      title: "秘籍详情"
    }
  },

  // 科二秘籍
  {
    name: "TwoEsoterica",
    path: "/TwoEsoterica/:type",
    component: () => import("../views/Homepage/TwoEsoterica.vue"),
    meta: {
      title: "科二秘籍"
    }
  },
  // 科二考点视频
  {
    name: "TestVideo",
    path: "/TestVideo/:type",
    component: () => import("../views/Homepage/TestVideo.vue"),
    meta: {
      title: "科二考点视频"
    }
  },
  // 科二视频详情
  {
    name: "TeachingVideo",
    path: "/TeachingVideo/:type/:id",
    component: () => import("../views/Homepage/TeachingVideo.vue")
  },

  // 考试流程
  {
    name: "TestProcess",
    path: "/TestProcess",
    component: () => import("../views/Homepage/TestProcess.vue"),
    meta: {
      title: "考试流程"
    }
  },

  // 考试标准
  {
    name: "TestStandard",
    path: "/TestStandard",
    component: () => import("../views/Homepage/TestStandard.vue"),
    meta: {
      title: "考试标准"
    }
  },

  // 模拟考试
  {
    name: "PracticeTest",
    path: "/PracticeTest/:type",
    component: () => import("../views/exam/PracticeTest.vue"),
    meta: {
      title: "模拟考试"
    }
  },

  // 基础操作
  {
    name: "BasicOperation",
    path: "/BasicOperation/:type",
    component: () => import("../views/Homepage/BasicOperation.vue"),
    meta: {
      title: "基础操作",
      keepAlive: true
    }
  },

  // 评论帖子详情
  {
    name: "PostsPage",
    path: "/PostsPage/:id",
    component: () => import("../views/Homepage/PostsPage.vue"),
    meta: {
      title: "帖子详情"
    }
  },

  {
    path: "/about",
    name: "About",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue")
  },

  // 定位
  {
    name: "Location",
    path: "/Location",
    component: () => import("../views/sign/Location.vue"),
    meta: {
      title: "定位"
    }
  },

  // 个人中心
  {
    path: "/Ucenter",
    name: "Ucenter",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/ucenter/Ucenter.vue"),
    meta: {
      title: "个人中心"
    }
  },

  // 搜一搜
  {
    name: "Search",
    path: "/Search",
    component: () => import("../views/search/Search.vue"),
    meta: {
      title: "搜一搜",
      keepAlive: true
    }
  },

  // 我的贷款
  {
    path: "user/Loans",
    name: "Loans",
    component: () => import("../views/ucenter/Loans.vue")
  },
  // 我的合同
  {
    name: "user/MyPact",
    path: "/MyPact",
    component: () => import("../views/ucenter/MyPact.vue"),
    meta: {
      title: "我的合同"
    }
  },

  // 消息列表
  {
    name: "user/ListItem",
    path: "/ListItem",
    component: () => import("../views/ucenter/ListItem.vue"),
    meta: {
      title: "消息列表"
    }
  },

  // 培训记录
  {
    name: "user/TrainingRecord",
    path: "/TrainingRecord",
    component: () => import("../views/ucenter/TrainingRecord.vue")
  },

  // 我要约车
  {
    name: "user/TaxiHailing",
    path: "/TaxiHailing",
    component: () => import("../views/ucenter/TaxiHailing/TaxiHailing.vue"),
    meta: {
      title: "我要约车"
    }
  },

  // 编辑订单
  {
    name: "OrmulaBar",
    path: "/OrmulaBar/:id",
    component: () => import("../views/ucenter/UcOrders/OrmulaBar.vue"),
    meta: {
      title: "编辑订单"
    }
  },

  // 查看订单
  {
    name: "CheckOrder",
    path: "/CheckOrder/:id",
    component: () => import("../views/ucenter/UcOrders/CheckOrder.vue"),
    meta: { title: "查看订单" }
  },

  // 我要补考
  {
    name: "MyExamination",
    path: "/MyExamination",
    component: () => import("../views/ucenter/MyExamination.vue"),
    meta: {
      title: "我要补考"
    }
  },

  // 服务中心
  {
    name: "user/ServiceCenter",
    path: "/ServiceCenter",
    component: () => import("../views/ucenter/ServiceCenter.vue"),
    meta: {
      text: "服务中心"
    }
  },

  // 设置
  {
    path: "/Set",
    name: "user/Set",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/ucenter/Set.vue"),
    meta: {
      title: "设置"
    }
  },

  // 修改银行卡
  {
    name: "BankCard",
    path: "/BankCard",
    component: () => import("../views/ucenter/ste/BankCard.vue")
  },

  // 基本信息
  {
    path: "/BasicInfo",
    name: "user/BasicInfo",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/ucenter/BasicInfo.vue"),
    meta: {
      title: "基本信息"
    }
  },
  // 立即登录

  // 验证码登录
  {
    name: "AuthCode",
    path: "/AuthCode",
    component: () => import("../views/ucenter/PersonalCenter/AuthCode.vue"),
    meta: {
      title: "验证码登录",
      keepAlive: true
    }
  },
  // 密码登录
  {
    name: "PasswprdLogo",
    path: "/PasswprdLogo",
    component: () => import("../views/ucenter/PersonalCenter/PasswprdLogo.vue"),
    meta: {
      title: "密码登录",
      keepAlive: true
    }
  },

  // 我的订单
  {
    path: "/UcOrders",
    name: "user/UcOrders",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/ucenter/UcOrders.vue"),
    meta: {
      title: "我的订单"
    }
  },

  // 订单评价
  {
    name: "Evaluate",
    path: "/Evaluate/:id",
    component: () => import("../views/ucenter/UcOrders/Evaluate.vue"),
    meta: {
      title: "订单评价"
    }
  },

  // 订单详情
  {
    name: "OrdersDetails",
    path: "/OrdersDetails/:id",
    component: () => import("../views/ucenter/UcOrders/OrdersDetails.vue"),
    meth: {
      title: "订单详情"
    }
  },

  // 我的账户
  {
    name: "user/MyAccount",
    path: "/MyAccount",
    component: () => import("../views/ucenter/MyAccount.vue"),
    meta: {
      title: "我的账户"
    }
  },

  // 充值提现
  {
    name: "TopUp",
    path: "/TopUp/:type",
    component: () => import("../views/ucenter/MyAccount/TopUp"),
    meta: {
      title: "提现充值"
    }
  },

  // 我的收藏
  {
    name: "user/MyFavorite",
    path: "/MyFavorite",
    component: () => import("../views/ucenter/MyFavorite.vue"),
    meta: {
      title: "我的收藏"
    }
  },

  // 错题收藏
  {
    name: "MistakesCollect",
    path: "/MistakesCollect",
    component: () => import("../views/exam/MistakesCollect.vue"),
    meta: {
      title: "错题"
    }
  },

  // 我要约课
  {
    path: "/SelectLesson",
    name: "SelectLesson",
    component: () =>
      import(
        /* webpackChunkName: "about" */ "../views/ucenter/SelectLesson.vue"
      ),
    meta: {
      title: "我要约课"
    }
  },

  // 约车列表
  {
    name: "stipulatedList",
    // stipulatedList
    path: "/stipulatedList/:id",
    component: () => import("../views/ucenter/TaxiHailing/stipulatedList.vue"),
    meta: {
      title: "约车列表"
    }
  },

  {
    path: "/SelectCoacHour",
    name: "SelectCoacHour",
    component: () =>
      import(
        /* webpackChunkName: "about" */ "../views/ucenter/SelectCoacHour.vue"
      ),
    meta: {
      title: "选择某个教练时间段"
    }
  },

  // 咨询
  {
    path: "/News",
    name: "News",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/news/News.vue"),
    meta: {
      title: "资讯",
      keepAlive: true
    }
  },

  // 咨询详情
  {
    path: "/NewsDetail/:id",
    name: "NewsDetail",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/news/NewsDetail.vue"),
    meta: {
      title: "资讯详情"
    }
  },

  // 找驾校
  {
    path: "/SignIndex",
    name: "SignIndex",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/sign/SignIndex.vue"),
    meta: {
      title: "找驾校"
    }
  },

  // 驾校详情
  {
    name: "DetailedPhotos",
    path: "/DetailedPhotos/:lid",
    component: () => import("../views/sign/DetailedPhotos.vue"),
    meta: {
      title: "驾校详情"
    }
  },

  // 驾校地图
  {
    name: "Cartography",
    path: "/Cartography/:jd/:wd",
    component: () => import("../views/sign/Cartography.vue")
  },

  // 班型详情
  {
    name: "BanksDetails",
    path: "/BanksDetails/:id",
    component: () => import("../views/sign/BanksDetails.vue"),
    meta: {
      title: "班型详情"
    }
  },

  // 免费咨询
  {
    name: "ChargEconsult",
    path: "/ChargEconsult/:id",
    component: () => import("../views/sign/ChargEconsult.vue"),
    meta: {
      title: "免费咨询"
    }
  },

  // 报名咨询
  {
    name: "ApplyOnline",
    path: "/ApplyOnline/:lid/:id",
    component: () => import("../views/sign/ApplyOnline.vue"),
    meta: {
      title: "在线报名",
      keepAlive: true
    }
  },

  // 认证
  {
    name: "IdentityAuthentication",
    path: "/IdentityAuthentication",
    component: () => import("../views/sign/IdentityAuthentication.vue"),
    meta: {
      title: "实名认证"
    }
  },

  // 在线支付
  {
    name: "OnlinePayment",
    path: "/OnlinePayment",
    component: () => import("../views/sign/OnlinePayment.vue"),
    meta: {
      title: "在线支付"
    }
  },

  // 云驾校合同
  {
    name: "Contract",
    path: "/Contract",
    component: () => import("../views/sign/Contract.vue"),
    meta: {
      title: "云驾校合同"
    }
  },

  // 全部班型
  {
    name: "AllBanks",
    path: "/AllBanks/:lid",
    component: () => import("../views/sign/AllBanks.vue"),
    meta: {
      title: "全部班型"
    }
  },

  // 全部场地
  {
    name: "ExaminationRoom",
    path: "/ExaminationRoom/:lid",
    component: () => import("../views/sign/ExaminationRoom.vue"),
    meta: {
      title: "全部场地"
    }
  },

  // 驾校详情的评论页
  {
    name: "AllComments",
    path: "/AllComments/:lid",
    component: () => import("../views/sign/AllComments.vue"),
    meta: {
      title: "点评"
    }
  },

  // 教练详情
  {
    path: "/CoachDetail/:lid/:id",
    name: "CoachDetail",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/sign/CoachDetail.vue"),
    meta: {
      title: "教练详情"
    }
  },

  // 陪练详情
  {
    path: "/AccPractice/:lid",
    name: "AccPractice",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/sign/AccPractice.vue"),
    meta: {
      title: "陪练详情"
    }
  },

  // 全部班型
  {
    name: "CoachBanks",
    path: "/CoachBanks/:lid",
    component: () => import("../views/sign/CoachBanks.vue")
  },

  // 教练简介
  {
    name: "CoachIntro",
    path: "/CoachIntro/:lid",
    component: () => import("../views/sign/CoachIntro.vue")
  },

  // 教学环境
  {
    name: "CoachEnvironment",
    path: "/CoachEnvironment/:lid",
    component: () => import("../views/sign/CoachEnvironment.vue")
  },

  // 教练评论
  {
    name: "CoachComment",
    path: "/CoachComment/:lid",
    component: () => import("../views/sign/CoachComment.vue")
  },

  // 驾校详情
  {
    path: "/SchoolDetail/:lid",
    name: "SchoolDetail",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/sign/SchoolDetail.vue"),
    meta: {
      title: "驾校详情"
    }
  },
  {
    path: "/ShopIndex",
    name: "ShopIndex",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/shop/ShopIndex.vue"),
    meta: {
      title: "商城"
    }
  },

  // 陪练
  {
    name: "LadderPlayer",
    path: "/LadderPlayer",
    component: () => import("../views/sign/LadderPlayer.vue")
  },

  {
    path: "/MockExam/:type",
    name: "MockExam",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/exam/MockExam.vue"),
    meta: {
      title: "模拟考试"
    }
  },
  {
    path: "/SequentialExam/:type",
    name: "SequentialExam",
    component: () =>
      import(
        /* webpackChunkName: "about" */ "../views/exam/SequentialExam.vue"
      ),
    meta: {
      title: "顺序考试"
    }
  },

  // 模拟考试
  {
    name: "PracticeQuestions",
    path: "/PracticeQuestions/:type",
    component: () => import("../views/exam/PracticeQuestions.vue"),
    meta: {
      title: "模拟考试"
    }
  },

  // 降价急售
  {
    name: "CutShort",
    path: "/CutShort",
    component: () => import("../views/shop/CutShort/CutShort.vue"),
    meta: { title: "降价急售" }
  },
  // 车辆详情
  {
    name: "vehicleDetails",
    path: "/vehicleDetails",
    component: () => import("../views/shop/CutShort/vehicleDetails.vue")
  },
  // 车讯详情
  {
    name: "TheDetails",
    path: "/TheDetails",
    component: () => import("../views/shop/TheCar/TheDetails.vue")
  },
  // 更多条件
  {
    name: "More",
    path: "/More",
    component: () => import("../views/shop/newCars/More.vue")
  },
  // 车辆概况
  {
    name: "VehicleProfile",
    path: "/VehicleProfile",
    component: () => import("../views/shop/newCars/VehicleProfile.vue")
  },
  // 经销商
  {
    name: "Dealer",
    path: "/Dealer",
    component: () => import("../views/shop/newCars/Dealer.vue")
  },
  // 筛选
  {
    name: "screen",
    path: "/screen/:lid",
    component: () => import("../views/sign/screen.vue")
  },
  // 扫一扫
  {
    name: "scan",
    path: "/scan",
    // component: () => import("../views/sign/scan.vue")
    component: () => import("../views/sign/search.vue")
  },
  // 找教练中筛选
  {
    name: "card",
    path: "/card",
    component: () => import("../views/sign/Card.vue")
  },

  // 修改密码
  {
    name: "changedPassword",
    path: "/changedPassword",
    component: () => import("../views/ucenter/ste/changedPassword.vue")
  },

  // 修改手机号
  {
    name: "changePhone",
    path: "/changePhone",
    component: () => import("../views/ucenter/ste/changePhone.vue"),
    meta: {
      title: "修改手机号"
    }
  },

  // 考试下的报名须知
  {
    name: "ApplyNotice",
    path: "/ApplyNotice",
    component: () => import("../views/Homepage/ApplyNotice.vue"),
    meta: {
      title: "报名须知"
    }
  },

  // 考试下的学车流程
  {
    name: "DrivingFlow",
    path: "/DrivingFlow",
    component: () => import("../views/Homepage/DrivingFlow.vue"),
    meta: {
      title: "学车流程"
    }
  },

  // 考试下的支付流程
  {
    name: "PayFlow",
    path: "/PayFlow",
    component: () => import("../views/Homepage/PayFlow.vue"),
    meth: {
      title: "支付流程"
    }
  },

  // 考试下的教学大纲
  {
    name: "Syllabus",
    path: "/Syllabus",
    component: () => import("../views/Homepage/Syllabus.vue"),
    meta: {
      title: "教学大纲"
    }
  },

  // 考试下的考试须知
  {
    name: "EnduranceTest",
    path: "/EnduranceTest",
    component: () => import("../views/Homepage/EnduranceTest.vue"),
    meta: {
      title: "考试须知"
    }
  },

  // 说明
  {
    name: "AccountFor",
    path: "/AccountFor",
    component: () => import("../views/sign/AccountFor.vue"),
    meta: {
      title: "说明"
    }
  },

  // 我的咨询 -> 地图
  {
    name: "GeographicalMap",
    path: "/GeographicalMap",
    component: () => import("../views/sign/GeographicalMap.vue")
  },

  // 首页 -> 科目二(社区)
  {
    name: "CommunityList",
    path: "/CommunityList/:type",
    component: () => import("../views/Homepage/CommunityList.vue"),
    meta: {
      title: "社区"
    }
  },

  // 创建帖子
  {
    name: "user/ReleasingNotices",
    path: "/ReleasingNotices/:type",
    component: () => import("../views/Homepage/ReleasingNotices.vue"),
    meta: {
      title: "创建帖子"
    }
  },

  // demo
  {
    name: "Demo",
    path: "/Demo",
    component: () => import("../views/sign/Demo.vue")
  }
];

const router = new VueRouter({
  routes
});

router.beforeEach((to, from, next) => {
  // console.log(to);
  let url = to.name.split("/");
  // console.log(url);
  if (
    url[0] == "user" &&
    !(sessionStorage.getItem("token") || localStorage.getItem("token"))
  ) {
    // next("AuthCode");
    router.push({ path: "AuthCode" });
    return;
  } else {
    next();
  }
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  // next();
});
export default router;
